public class Solution972 {
    public boolean isRationalEqual(String s, String t) {
        s=dealDot(s);
        t=dealDot(t);
        s=dealLast9(s);
        t=dealLast9(t);
        int a=findZ(s);
        int b=findZ(t);
        if (a!=b){
            return false;
        }
        s=dealLast0(s);
        t=dealLast0(t);
        if (s.contains("(") && !t.contains("(") || !s.contains("(") && t.contains("(")){
            return false;
        }
        if (!s.contains("(") && !t.contains("(")){
            return s.equals(t);
        }
        s=dealCircle(s);
        t=dealCircle(t);
        return s.equals(t);
    }

    private String dealDot(String t) {
        if (t.charAt(t.length()-1)=='.'){
            return t.substring(0,t.length()-1);
        }else {
            return t;
        }
    }

    private String dealCircle(String t) {
        String m=t.substring(t.indexOf(".")+1,t.indexOf("("));
        String n=t.substring(t.indexOf("(")+1,t.indexOf(")"));
        int l=0;
        StringBuilder stringBuilder=new StringBuilder(m);
        while (stringBuilder.length()<100){
            stringBuilder.append(n.charAt(l));
            l=(l+1)%n.length();
        }
        return stringBuilder.toString();
    }

    private String dealLast0(String t) {
        if (t.contains("(")){
            int m=t.indexOf("(");
            String tt=t.substring(m+1,t.length()-1);
            boolean f=true;
            for (char c : tt.toCharArray()) {
                if (c!='0'){
                    f=false;
                    break;
                }
            }
            if (f) {
                t=t.substring(0, m);
            }
        }
        while (t.contains(".") && t.charAt(t.length()-1)=='0'){
            t=t.substring(0,t.length()-1);
        }
        t=dealDot(t);
        return t;
    }

    private int findZ(String t) {
        if (t.contains(".")){
            return Integer.parseInt(t.substring(0,t.indexOf(".")));
        }else {
            return Integer.parseInt(t);
        }
    }

    private String dealLast9(String t) {
        if (t.contains("(")){
            int m=t.indexOf("(");
            String tt=t.substring(m+1,t.length()-1);
            boolean f=true;
            for (char c : tt.toCharArray()) {
                if (c!='9'){
                    f=false;
                    break;
                }
            }
            if (f){
                int l=t.indexOf(".");
                StringBuilder stringBuilder=new StringBuilder(t);
                for (int i=m-1;i>l;i--){
                    if (stringBuilder.charAt(i)>='0' && stringBuilder.charAt(i)<='8'){
                        stringBuilder.setCharAt(i,(char)(stringBuilder.charAt(i)+1));
                        while (stringBuilder.length()>i+1){
                            stringBuilder.deleteCharAt(stringBuilder.length()-1);
                        }
                        return stringBuilder.toString();
                    }
                }
                int n=Integer.parseInt(t.substring(0,l));
                return String.valueOf(++n);
            }else {
                return t;
            }
        }else {
            return t;
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution972().isRationalEqual("0.(0)","0"));
    }
}
